/***********************************************************************
filename: 	CEGUIWindowProperties.cpp
created:	5/7/2004
author:		Paul D Turner

purpose:	Implementation of available window base class properties
*************************************************************************/

#include "hgeGuiWindowProperties.h"
#include "hgeGuiWindow.h"
#include "hgeFont.h"
#include "hgePropertyHelper.h"
#include "hgeExceptions.h"
#include "hgeGuiWindowFactoryManager.h"
#include <cstdlib>
#include <cstdio>

// Start of WindowProperties namespace section
namespace WindowProperties
{
	String ID::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::uintToString(static_cast<const Window*>(receiver)->getID());
	}

	void ID::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setID(PropertyHelper::stringToUint(value));
	}

	String Alpha::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::floatToString(static_cast<const Window*>(receiver)->getAlpha());
	}


	void Alpha::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setAlpha(PropertyHelper::stringToFloat(value));
	}


	String Font::get(const PropertyReceiver* receiver) const
	{
		const hgeFont* fnt = static_cast<const Window*>(receiver)->getFont();

		if (fnt)
		{
			return fnt->getName();
		}
		else
		{
			return String();
		}

	}


	void Font::set(PropertyReceiver* receiver, const String& value)
	{
		try
		{
			if (value.empty())
			{
				static_cast<Window*>(receiver)->setFont(0);
			}
			else
			{
				static_cast<Window*>(receiver)->setFont(value);
			}
		}
		catch (UnknownObjectException&)
		{ }
	}

	bool Font::isDefault(const PropertyReceiver* receiver) const
	{
		return static_cast<const Window*>(receiver)->getFont(false) == 0;
	}


	String Text::get(const PropertyReceiver* receiver) const
	{
		return static_cast<const Window*>(receiver)->getText();
	}


	void Text::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setText(value);
	}

	String MouseCursorImage::get(const PropertyReceiver* receiver) const
	{
		HCURSOR cursor = static_cast<const Window*>(receiver)->getMouseCursor();

		if (cursor)
		{
			return PropertyHelper::CursorToString(cursor);
		}
		else
		{
			return String();
		}

	}

	void MouseCursorImage::set(PropertyReceiver* receiver, const String& value)
	{
		if (!value.empty())
		{
			static_cast<Window*>(receiver)->setMouseCursor(value);
		}
	}

	bool MouseCursorImage::isDefault(const PropertyReceiver* receiver) const
	{
		return static_cast<const Window*>(receiver)->getMouseCursor(false) == 0;
	}


	String ClippedByParent::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isClippedByParent());
	}


	void ClippedByParent::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setClippedByParent(PropertyHelper::stringToBool(value));
	}


	String InheritsAlpha::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->inheritsAlpha());
	}


	void InheritsAlpha::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setInheritsAlpha(PropertyHelper::stringToBool(value));
	}


	String AlwaysOnTop::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isAlwaysOnTop());
	}


	void AlwaysOnTop::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setAlwaysOnTop(PropertyHelper::stringToBool(value));
	}


	String Disabled::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isDisabled());
	}


	void Disabled::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setEnabled(!PropertyHelper::stringToBool(value));
	}

	bool Disabled::isDefault(const PropertyReceiver* receiver) const
	{
		return !static_cast<const Window*>(receiver)->isDisabled(true);
	}


	String Visible::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isVisible());
	}


	void Visible::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setVisible(PropertyHelper::stringToBool(value));
	}

	bool Visible::isDefault(const PropertyReceiver* receiver) const
	{
		return static_cast<const Window*>(receiver)->isVisible(true);
	}


	String RestoreOldCapture::get(const PropertyReceiver* receiver) const
	{
		return	PropertyHelper::boolToString(static_cast<const Window*>(receiver)->restoresOldCapture());
	}


	void RestoreOldCapture::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setRestoreCapture(PropertyHelper::stringToBool(value));
	}


	String DestroyedByParent::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isDestroyedByParent());
	}


	void DestroyedByParent::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setDestroyedByParent(PropertyHelper::stringToBool(value));
	}


	String ZOrderChangeEnabled::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isZOrderingEnabled());
	}


	void ZOrderChangeEnabled::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setZOrderingEnabled(PropertyHelper::stringToBool(value));
	}


	String WantsMultiClickEvents::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->wantsMultiClickEvents());
	}


	void WantsMultiClickEvents::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setWantsMultiClickEvents(PropertyHelper::stringToBool(value));
	}


	String MouseButtonDownAutoRepeat::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isMouseAutoRepeatEnabled());
	}


	void MouseButtonDownAutoRepeat::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setMouseAutoRepeatEnabled(PropertyHelper::stringToBool(value));
	}


	String AutoRepeatDelay::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::floatToString(static_cast<const Window*>(receiver)->getAutoRepeatDelay());
	}


	void AutoRepeatDelay::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setAutoRepeatDelay(PropertyHelper::stringToFloat(value));
	}


	String AutoRepeatRate::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::floatToString(static_cast<const Window*>(receiver)->getAutoRepeatRate());
	}


	void AutoRepeatRate::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setAutoRepeatRate(PropertyHelper::stringToFloat(value));
	}


	String DistributeCapturedInputs::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->distributesCapturedInputs());
	}


	void DistributeCapturedInputs::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setDistributesCapturedInputs(PropertyHelper::stringToBool(value));
	}

	String RiseOnClick::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isRiseOnClickEnabled());
	}


	void RiseOnClick::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setRiseOnClickEnabled(PropertyHelper::stringToBool(value));
	}


	String VerticalAlign::get(const PropertyReceiver* receiver) const
	{
		switch(static_cast<const Window*>(receiver)->getVerticalAlignment())
		{
		case VA_CENTRE:
			return String("Centre");
			break;

		case VA_BOTTOM:
			return String("Bottom");
			break;

		default:
			return String("Top");
		}
	}

	void VerticalAlign::set(PropertyReceiver* receiver, const String& value)
	{
		VerticalAlignment align;

		if (value == "Centre")
		{
			align = VA_CENTRE;
		}
		else if (value == "Bottom")
		{
			align = VA_BOTTOM;
		}
		else
		{
			align = VA_TOP;
		}

		static_cast<Window*>(receiver)->setVerticalAlignment(align);
	}


	String HorizontalAlign::get(const PropertyReceiver* receiver) const
	{
		switch(static_cast<const Window*>(receiver)->getHorizontalAlignment())
		{
		case HA_CENTRE:
			return String("Centre");
			break;

		case HA_RIGHT:
			return String("Right");
			break;

		default:
			return String("Left");
		}
	}

	void HorizontalAlign::set(PropertyReceiver* receiver, const String& value)
	{
		HorizontalAlignment align;

		if (value == "Centre")
		{
			align = HA_CENTRE;
		}
		else if (value == "Right")
		{
			align = HA_RIGHT;
		}
		else
		{
			align = HA_LEFT;
		}

		static_cast<Window*>(receiver)->setHorizontalAlignment(align);
	}


	String MousePassThroughEnabled::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(static_cast<const Window*>(receiver)->isMousePassThroughEnabled());
	}

	void MousePassThroughEnabled::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setMousePassThroughEnabled(PropertyHelper::stringToBool(value));
	}
	
	//----------------------------------------------------------------------------//
	String AutoRenderingSurface::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(
			static_cast<const Window*>(receiver)->isUsingAutoRenderingSurface());
	}

	//----------------------------------------------------------------------------//
	void AutoRenderingSurface::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setUsingAutoRenderingSurface(
			PropertyHelper::stringToBool(value));
	}

	//----------------------------------------------------------------------------//
	String Rotation::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::vector3ToString(
			static_cast<const Window*>(receiver)->getRotation());
	}

	//----------------------------------------------------------------------------//
	void Rotation::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setRotation(
			PropertyHelper::stringToVector3(value));
	}

	//----------------------------------------------------------------------------//
	String XRotation::get(const PropertyReceiver* receiver) const
	{
		const Vector3 v(static_cast<const Window*>(receiver)->getRotation());
		return PropertyHelper::floatToString(v.d_x);
	}

	//----------------------------------------------------------------------------//
	void XRotation::set(PropertyReceiver* receiver, const String& value)
	{
		const float v = PropertyHelper::stringToFloat(value);
		Vector3 r(static_cast<const Window*>(receiver)->getRotation());
		r.d_x = v;
		static_cast<Window*>(receiver)->setRotation(r);
	}

	//----------------------------------------------------------------------------//
	String YRotation::get(const PropertyReceiver* receiver) const
	{
		const Vector3 v(static_cast<const Window*>(receiver)->getRotation());
		return PropertyHelper::floatToString(v.d_y);
	}

	//----------------------------------------------------------------------------//
	void YRotation::set(PropertyReceiver* receiver, const String& value)
	{
		const float v = PropertyHelper::stringToFloat(value);
		Vector3 r(static_cast<const Window*>(receiver)->getRotation());
		r.d_y = v;
		static_cast<Window*>(receiver)->setRotation(r);
	}

	//----------------------------------------------------------------------------//
	String ZRotation::get(const PropertyReceiver* receiver) const
	{
		const Vector3 v(static_cast<const Window*>(receiver)->getRotation());
		return PropertyHelper::floatToString(v.d_z);
	}

	//----------------------------------------------------------------------------//
	void ZRotation::set(PropertyReceiver* receiver, const String& value)
	{
		const float v = PropertyHelper::stringToFloat(value);
		Vector3 r(static_cast<const Window*>(receiver)->getRotation());
		r.d_z = v;
		static_cast<Window*>(receiver)->setRotation(r);
	}

	//----------------------------------------------------------------------------//
	String NonClient::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(
			static_cast<const Window*>(receiver)->isNonClientWindow());
	}

	//----------------------------------------------------------------------------//
	void NonClient::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->
			setNonClientWindow(PropertyHelper::stringToBool(value));
	}

	//----------------------------------------------------------------------------//
	String TextParsingEnabled::get(const PropertyReceiver* receiver) const
	{
		return PropertyHelper::boolToString(
			static_cast<const Window*>(receiver)->isTextParsingEnabled());
	}

	void TextParsingEnabled::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->
			setTextParsingEnabled(PropertyHelper::stringToBool(value));
	}

	//----------------------------------------------------------------------------//
	String RendererProperty::get(const PropertyReceiver* receiver) const
	{
		WindowRenderer* wr = static_cast<const Window*>(receiver)->getWindowRenderer();
		return wr ? wr->getName() : "";
	}

	void RendererProperty::set(PropertyReceiver* receiver, const String& value)
	{
		static_cast<Window*>(receiver)->setWindowRenderer(value);
	}

} // End of  WindowProperties namespace section
